package cn.zz.veggie.web.controller.mgmt;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.lang.UUID;
import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.core.types.result.PageResult;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.AdminAppService;
import cn.zz.veggie.web.types.dto.mgmt.MgmtAdminLoginDto;
import cn.zz.veggie.web.types.dto.mgmt.admin.MgmtAdminQueryDto;
import cn.zz.veggie.web.types.vo.LoginTokenVo;
import cn.zz.veggie.web.types.vo.mgmt.AdminLoginInfoVo;
import cn.zz.veggie.web.types.vo.mgmt.admin.MgmtAdminVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * 管理端/管理员
 *
 * @author zhongq
 * @since 2024/5/13
 */
@Validated
@RestController
@BoxRespResult
@RequiredArgsConstructor
@RequestMapping("/mgmt/admin")
public class MgmtAdminController {

	private final AdminAppService adminAppService;

	/**
	 * 管理员登陆
	 * <p>
	 * ACCOUNT_PASSWORD_ERROR 用户名或密码错误
	 */
	@PostMapping("/login")
	public LoginTokenVo login(@RequestBody @Validated MgmtAdminLoginDto dto) {
		return new LoginTokenVo(UUID.randomUUID().toString(true));
	}

	/**
	 * 获取登陆信息
	 */
	@GetMapping("/info")
	public AdminLoginInfoVo info() {
		final AdminLoginInfoVo vo = new AdminLoginInfoVo();
		vo.setUsername("zq");
		return vo;
	}

	@GetMapping("/list")
	public PageResult<MgmtAdminVo> adminList(@Validated MgmtAdminQueryDto dto,
			@RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return adminAppService.adminGetAdminList(dto, PageQuery.of(current, size));
	}
}